package com.myh.testlogin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.myh.testlogin.entity.User;
import com.myh.testlogin.mapper.UserMapper;
import com.myh.testlogin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 作者：莫耀华
 * @since 2020-09-16
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 登录方法
     * @param username 用户名
     * @return
     */
    @Override
    public User loginByUserName(String username) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        queryWrapper.eq("username",username);
        User user = userMapper.selectOne(queryWrapper);
        return user;
    }

    /**
     * 修改用户密码
     * @param id 用户唯一id
     * @param newPassword 新密码
     * @return
     */
    @Override
    public int updatePwdById(Integer id,String newPassword) {
        User user =new User();
        user.setId(id);
        user.setPassword(newPassword);
        return userMapper.updateById(user);
    }
}
